$(document).ready(function(){
  $(window).scroll(function () {
      var top = $(document).scrollTop();
       
      if(top > 50)
        $('#btn-goto-top').show();
      else
        $('#btn-goto-top').hide();
  });
//取消a的默认点击动作
  $("a[href='#']").click(function(e) {
    e.preventDefault();
  });
  //SwitchPageTitle();
});

// function cleanSource(html) {
//   var lines = html.split(/\n/);

//   lines.shift();
//   lines.splice(-1, 1);

//   var indentSize = lines[0].length - lines[0].trim().length,
//       re = new RegExp(" {" + indentSize + "}");

//   lines = lines.map(function(line){
//     if (line.match(re)) {
//       line = line.substring(indentSize);
//     }

//     return line;
//   });

//   lines = lines.join("\n");

//   return lines;
// }

function SwitchPageTitle(){
  $(".page-title").slideToggle();
  $(".user-info-navbar").slideToggle();
  var vis = $('.page-title-close').css("margin-top") == "-50px";
  if(vis){
    $('.page-title-close').css({"margin-top":"-20px","margin-bottom":"10px"});
    $('#page-title-close-icon').attr("class","fa-angle-double-down");
  }
  else{
    $('.page-title-close').css({"margin-top":"-50px","margin-bottom":"30px"});
    $('#page-title-close-icon').attr("class","fa-angle-double-up");
  }
}

function showInputError(msg, ctrl, callback, timeout){    
    $('#msg-submit-result').removeClass('alert-danger');
    $('#msg-submit-result').removeClass('alert-success');
    $('#msg-submit-result').addClass('alert-danger');
    $('#msg-submit-result').html(msg).show();
    if(ctrl){
        $('#'+ctrl).parent().addClass('validate-has-error');
    }
    
    setTimeout(function(){
        $('#msg-submit-result').fadeOut("normal");
        if(callback){
          callback();
        }
    },timeout||3000);
}
function showInputSuccess(msg, callback,timeout){    
    $('#msg-submit-result').removeClass('alert-danger');
    $('#msg-submit-result').removeClass('alert-success');
    $('#msg-submit-result').addClass('alert-success');
    $('#msg-submit-result').html(msg).show();
    
    setTimeout(function(){
        $('#msg-submit-result').fadeOut();
        if(callback){
          callback();
        }
    },timeout||5000);
}
if (!Array.prototype.includes) {
  Array.prototype.includes = function(searchElement /*, fromIndex*/) {
    'use strict';
    if (this == null) {
      throw new TypeError('Array.prototype.includes called on null or undefined');
    }

    var O = Object(this);
    var len = parseInt(O.length, 10) || 0;
    if (len === 0) {
      return false;
    }
    var n = parseInt(arguments[1], 10) || 0;
    var k;
    if (n >= 0) {
      k = n;
    } else {
      k = len + n;
      if (k < 0) {k = 0;}
    }
    var currentElement;
    while (k < len) {
      currentElement = O[k];
      if (searchElement === currentElement ||
         (searchElement !== searchElement && currentElement !== currentElement)) { // NaN !== NaN
        return true;
      }
      k++;
    }
    return false;
  };
}

Date.prototype.Format = function (fmt) { //author: meizz 
    var o = {
        "M+": this.getMonth() + 1, //月份 
        "d+": this.getDate(), //日 
        "h+": this.getHours(), //小时 
        "m+": this.getMinutes(), //分 
        "s+": this.getSeconds(), //秒 
        "q+": Math.floor((this.getMonth() + 3) / 3), //季度 
        "S": this.getMilliseconds() //毫秒 
    };
    if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
    for (var k in o)
    if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
    return fmt;
}